﻿using System;
using System.Linq;
using System.Text;
using System.Activities;
using System.Activities.Expressions;
using System.Activities.Presentation.PropertyEditing;
using System.Activities.Statements;
using System.Collections.Generic;
using System.ComponentModel;
using Core = Vision.Core;

namespace Vision.Core.ActivityComponents.Activities
{
    /// <summary>
    /// 
    /// </summary>
    public class SendVisionActivityMessage : CodeActivity
    {
        /// <summary>
        /// 
        /// </summary>
        [DefaultValue(null)]
        public InArgument<string> QueuePath { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [DefaultValue(null)]
        public InArgument<Guid> ActivityKey { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [DefaultValue(null)]
        public InArgument<Dictionary<string, object>> ActivityParams { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        protected override void Execute(CodeActivityContext context)
        {                        
            Core.Entities.Activities.VisionActivityMessage eqMessage = new Core.Entities.Activities.VisionActivityMessage();
            eqMessage.ActivityParams = new Entities.Activities.VisionActivityParameterCollection();
            eqMessage.ActivityKey = context.GetValue(this.ActivityKey);                           

            Dictionary<string, object> inputParams = context.GetValue(this.ActivityParams);
            if (inputParams != null){
                foreach (string key in inputParams.Keys){
                    eqMessage.ActivityParams.Add(key, inputParams[key]);    
                }
            }
            
            using (Components.ActivityQueueSender queueSender = new Components.ActivityQueueSender(context.GetValue(this.QueuePath))){
                queueSender.SendVisionActivityMessage(eqMessage);    
            }                        
        }
    }
}
